package com.dt76.smallloanbackenduser.controller.lhuaw;

import com.dt76.smallloanbackenduser.remote.lhuaw.UserFeedbacktest;
import com.dt76.smallloanbackenduser.utils.Page;
import com.dt76.smallloanbackenduser.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

//
//import com.dt76.smallloanbackenduser.remote.lhuaw.UserFeedbacktest;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.stereotype.Controller;
//import org.springframework.ui.Model;
//import org.springframework.web.bind.annotation.RequestMapping;
//
@Controller
@RequestMapping("/lhuaw")
public class UserFeedbackController {
    @Autowired
    private UserFeedbacktest userFeedbacktest;
//
    @RequestMapping("/qryAllFeedback")
    public String qryAllFeedback(Model model){
        model.addAttribute("qryuserFeedbackList",userFeedbacktest.qryAllFeedback());
//        System.out.println("调用成功");
        System.out.println(userFeedbacktest.qryAllFeedback());
        return "pages/lhuaw/FeedbackUsers";
    }
    @RequestMapping("/qryConditionPageAllFeedback")
    public String qryConditionPageAllFeedback(Model model, Integer currentPageNo,
                                              @RequestParam(value ="userName",required = false)String userName,
                                              @RequestParam(value = "feedbackQuestion",required = false)String feedbackQuestion
    ){
        if (currentPageNo <= 0) {
            currentPageNo = 1;
        }
        String paramuserName= "";
        String paramfeedbackQuestion="";
        if(userName != null && ! userName.equals("")){
            paramuserName ="%"+userName+"%";
        }
        if(feedbackQuestion !=null && ! feedbackQuestion.equals("")){
            paramfeedbackQuestion ="%"+feedbackQuestion+"%";
        }
        Page page = userFeedbacktest.qryConditionPageAllFeedback(currentPageNo,paramuserName,paramfeedbackQuestion);
        model.addAttribute("userFeedbackList",page.getRows());
        model.addAttribute("page",page);
        model.addAttribute("userName",userName);
        model.addAttribute("feedbackQuestion",feedbackQuestion);
        System.out.println(page.getRows());
        return "pages/lhuaw/FeedbackUsers";
    }
    @RequestMapping("/deleteFeedback/{ufId}")
    @ResponseBody
    public Result delete(@PathVariable String ufId){
        return userFeedbacktest.deleteFeedback(Integer.parseInt(ufId));
    }
//
}
